package query

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

/**
默认的一般get请求，例如：http://www.abc.com?username=efg
*/
func Default(c *gin.Context) {
	query := c.DefaultQuery("username", "")
	// query := c.Query("username")
	c.String(http.StatusOK, "query string is: "+query)
}

/**
get请求字符串为数组，例如：http://www.abc.com?ids=1&ids=2&ids=3
*/
func QueryArr(c *gin.Context) {
	query := c.QueryArray("ids")

	fmt.Printf("query arr is: %v", query)
	c.String(http.StatusOK, "query string in fmt")
}

func QueryMap(c *gin.Context) {
	query := c.QueryMap("status")

	fmt.Printf("query map is: %v", query)
	c.String(http.StatusOK, "query string in fmt")
}

type People struct {
	FirstName  string `form:"firstName" json:"firstName"`
	SecondName string `form:"secondName" json:"secondName"`
}

func QueryJson(c *gin.Context) {
	var people People
	_ = c.ShouldBindJSON(&people)
	fmt.Println(people)
	fmt.Println(people.FirstName)
	c.String(http.StatusOK, "query string in fmt")
}
